<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=0">
    <title>用户登录</title>
    <link rel="stylesheet" href="/static/style.css">
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <style>
        form {
            width: 310px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
<div class="login-page">
    <h1 class="login-title">投票登录</h1>
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item" pane>
            <label for="jobNumber" class="layui-form-label">工号</label>
            <div class="layui-input-block">
                <input id="jobNumber" class="layui-input" type="text">
            </div>
        </div>
        <div class="layui-form-item" pane>
            <label class="layui-form-label" for="password">密码</label>
            <div class="layui-input-block">
                <input class="layui-input" id="password" type="password">

            </div>
        </div>
        <!--                <div class="login-input">-->
        <!--                    <label for="verify">验证码</label>-->
        <!--                    <input id="verify" type="text">-->
        <!--                    <img src="#" alt="">-->
        <!--                </div>-->
        <div class="login-submit">
            <button type="button" class="layui-btn">登录</button>
        </div>
    </form>
</div>
<script src="/static/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/lib/model/'
    }).use(['jquery', 'layer'], function () {
        var $ = layui.$
            , lauer = layui.layer;
        $('.login-submit').click(function () {
            // 获取表单提交的信息
            var jobNumber = $("#jobNumber").val()
                , password = $("#password").val();
            // 提交表单信息
            $.ajax({
                type: 'POST'
                , url: '/user/login'
                , contentType: 'application/json'
                , data: JSON.stringify({jobNumber: jobNumber, password: password})
                , success: function (res) {
                    if (res.status == 200) {
                        if (res.data == "" || res.data == null) {
                            layer.alert(res.msg, {
                                skin: 'layui-layer-lan'
                                , closeBtn: 0
                                , anim: 1 //动画类型
                            });
                        } else {
                            layer.msg(res.msg, {icon: 1, time: 1000, offset: '100px'}, function () {
                                window.location.href = res.data;
                            })
                        }
                    } else {
                        layer.alert(res.msg, {
                            skin: 'layui-layer-red'
                            , closeBtn: 0
                            , anim: 0 //动画类型
                        });
                    }
                }
            })
        })
    });
</script>
</body>
</html>